package com.huike.service.dictionaries.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.huike.dto.DictDatePageDTO;
import com.huike.dto.DictTypeDTO;
import com.huike.dto.DictionariesPageDTO;
import com.huike.mapper.dictionaries.DictionariesMapper;
import com.huike.result.PageResult;
import com.huike.result.Result;
import com.huike.service.dictionaries.DictionariesService;
import com.huike.vo.DictDateVO;
import com.huike.vo.DictPageVO;
import com.huike.vo.DictionariesVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class DictionariesServiceImpl implements DictionariesService {
    @Autowired
    private DictionariesMapper dictionariesMapper;

    //字典查询
    @Override
    public PageResult selectList(DictionariesPageDTO dto) {
        if (null == dto.getPageSize() || null == dto.getPageNum() || dto.getPageNum() <= 0 || dto.getPageSize() <= 0) {
            dto.setPageNum(1);
            dto.setPageSize(100);
        }
        PageHelper.startPage(dto.getPageNum(), dto.getPageSize());
        Page<DictionariesVO> page = dictionariesMapper.selectList(dto);
        return new PageResult(page.getTotal(), page.getResult(), 200, "查询成功", "");
    }

    //根据id查询字典
    @Override
    public DictionariesVO   selectById(Long id) {
        return dictionariesMapper.selectById(id);
    }
    //根据状态查询字典标签
    @Override
    public Result<List<DictDateVO>> selectByStatus(String status) {
        List<DictDateVO>list = dictionariesMapper.selectByStatus(status);
        return Result.success(list);

    }
    //字典标签分页查询
    @Override
    public PageResult selectDateList(DictDatePageDTO dto) {
        if (null == dto.getPageSize() || null == dto.getPageNum() || dto.getPageNum() <= 0 || dto.getPageSize() <= 0) {
            dto.setPageNum(1);
            dto.setPageSize(10);
        }
        PageHelper.startPage(dto.getPageNum(),dto.getPageSize());
        Page<DictDateVO>page= dictionariesMapper.selectDateList(dto);
        return new PageResult(page.getTotal(), page.getResult(),200,"查询成功","");
        
    }
    //字典新增
    @Override
    public void dictTypeSave(DictPageVO vo) {
        vo.setCreateTime(LocalDateTime.now());
        vo.setUpdateTime(LocalDateTime.now());
        dictionariesMapper.dictTypeSave(vo);
    }
    //字典删除
    @Override
    public void dictTypeDelect(List<Long> ids) {
        dictionariesMapper.dictTypeDelect(ids);
    }
    //字典修改
    @Override
    public void dictTypeUpdate(DictTypeDTO dto) {
        dto.setUpdateTime(LocalDateTime.now());
        dictionariesMapper.dictTypeUpdate(dto);
    }
    //新增字典标签功能
    @Override
    public void dictDateSave(DictDateVO vo) {
        vo.setCreateTime(LocalDateTime.now());
        vo.setUpdateTime(LocalDateTime.now());
        dictionariesMapper.dictDateSave(vo);
    }
    //根据id查询字典标签功能
    @Override
    public DictDateVO dictDateSelectById(Long id) {

        return  dictionariesMapper.dictDateSelectById(id);
    }
    //修改字典标签功能
    @Override
    public void dictDateUpdate(DictDateVO dto) {

        dictionariesMapper.dictDateUpdate(dto);
    }

    @Override
    public void dictDateDelect(List<Long> ids) {
        dictionariesMapper.dictDateDelect(ids);
    }


}
